package com.zd.web.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zd.entity.Novel;
import com.zd.service.AddWriterNovelService;
import com.zd.service.impl.AddWriterNovelServiceImpl;

/**
 * Servlet implementation class AddwriternovelServlet
 */
@WebServlet("/AddwriternovelServlet")
public class AddwriternovelServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public AddwriternovelServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		String imgURL=request.getParameter("imgURL");
		String novelname=request.getParameter("novelname");
		String sort1=request.getParameter("sort1");
		String sort2=request.getParameter("sort2");
		if(sort1.equals(sort2)) {
			request.setAttribute("falseym", "不能选择同一个类型");
			request.getRequestDispatcher("writerNovel.jsp").forward(request, response);
			return;
		}
		String introduction=request.getParameter("introduction");
		System.out.println("我的"+sort1);
		Novel novel=new Novel();
		novel.setNovelName(novelname);
		novel.setNovelImgURL(imgURL);
		novel.setAudit(0);
		novel.setNovelIntroduction(introduction);
		novel.setNovelType1(sort1);
		novel.setNovelType2(sort2);
		AddWriterNovelService addwriternovelservice=new AddWriterNovelServiceImpl();
		int row=addwriternovelservice.addnovel(novel);
//		request.getRequestDispatcher("writeradmin.jsp").forward(request, response);
		response.sendRedirect("WriterCenterServlet");
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
